package com.xxwy.bean.definition;

import com.xxwy.bean.User;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.GenericBeanDefinition;

/**
 * @author wy
 * @date 2020/4/21 10:35
 */
public class BeanDefinitionCreateDemo {

  public static void main(String[] args) {

    //1.通过BeanDefinitionBuilder构建
    AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(User.class)
        .addPropertyValue("name", "baba")
        .addPropertyValue("age", "16").getBeanDefinition();

    //class [com.xxwy.bean.User];
    // scope=; abstract=false; lazyInit=null; autowireMode=0;
    // dependencyCheck=0; autowireCandidate=true; primary=false;
    // factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null
    System.out.println(beanDefinition);

    //2.通过AbstractBeanDefinition
    GenericBeanDefinition genericBeanDefinition = new GenericBeanDefinition();
    genericBeanDefinition.setBeanClass(User.class);
    // 通过MutablePropertyValues批量操作
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("name","mama");
    propertyValues.add("age","18");
    genericBeanDefinition.setPropertyValues(propertyValues);


  }
}
